package tk.kolesnikov.algorithms;

public class HammingHelper {

    public static int getHammingDistance(String first, String second) {
        if (first.length() != second.length())
            throw new IllegalArgumentException("Strings should have the same length");

        int distance = 0;
        for (int i = 0; i < first.length(); i++)  {
            if (first.charAt(i) != second.charAt(i)) distance++;
        }
        return distance;
    }

    public static int getHammingDistance(int first, int second) {
        return getHammingDistance(Integer.toBinaryString(first), Integer.toBinaryString(second));
    }

}
